package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserEcologyCastUpperLimit;
import com.sc.nft.entity.UserEcologyHatchUpperLimit;
import com.sc.nft.mapper.UserEcologyHatchUpperLimitMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * @author 朱梦晨
 * @Description:
 * @date 2024-08-08
 */
@Slf4j
@Repository
public class UserEcologyHatchUpperLimitDao extends ServiceImpl<UserEcologyHatchUpperLimitMapper, UserEcologyHatchUpperLimit> {



    public UserEcologyHatchUpperLimit getOneByUserIdAndCollectionId(Long userId, Long collectionId) {
        LambdaQueryWrapper<UserEcologyHatchUpperLimit> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserEcologyHatchUpperLimit::getUserId, userId);
        wrapper.eq(UserEcologyHatchUpperLimit::getCollectionId, collectionId);
        wrapper.eq(UserEcologyHatchUpperLimit::getIsDelete,Boolean.FALSE);
        wrapper.last("order by id  desc limit 1");
        return getOne(wrapper);
    }


    public Boolean addCountByUserIdAndCollectionId(Long userId, Long collectionId, Integer count) {
        LambdaUpdateWrapper<UserEcologyHatchUpperLimit> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(UserEcologyHatchUpperLimit::getUserId, userId);
        wrapper.eq(UserEcologyHatchUpperLimit::getCollectionId, collectionId);
        wrapper.eq(UserEcologyHatchUpperLimit::getIsDelete,Boolean.FALSE);
        wrapper.setSql("usable_count = usable_count + " + count);
        return update(wrapper);
    }

    public boolean subCountByUserIdAndCollectionId(Long userId, Long collectionId, Integer count) {
        return baseMapper.subCountByUserIdAndCollectionId(userId, collectionId, count);
    }




}
